package net.dfrz.lightshare.login.controller;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import net.dfrz.lightshare.login.service.LoginServiceImpl;
import net.dfrz.lightshare.user.model.User;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5728213299621190701L;
	
	
	private User user;
	private LoginServiceImpl limp;
	
	public String login(){
		return SUCCESS;
	}
	
	public String checkLogin(){
		HttpServletRequest request = ServletActionContext.getRequest();
		limp = new LoginServiceImpl();
		//TODO 调用 service进行校验
		//TODO 根据返回结果判断跳转
		System.out.println(user);
		String s = limp.checkLogin(user);
		if(s.equals("SUCCESS")){
			return SUCCESS;
		}
		else{
			if(s.equals("MULL")){
				request.setAttribute("tipMessage", "账户不存在");
			}
			else if(s.equals("NULL")){
				request.setAttribute("tipMessage", "密码错误");
			}
		}
		return "input";
	}
	
	public String index(){
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
